package com.homework1;

import java.util.Properties;
import javax.mail.Sessions;

public class SendMail implements Runnable {
    
    final String username =  "cyber_street@hotmail.com";
    final String password = "shebek";
    
    

    @Override
    public void run() {
	
	Properties props = new Properties();
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.starttls.enable", "true");
	props.put("mail.smtp.host", "smtp.hotmail.com");
	props.put("mail.smtp.port", "587");

	Session session = Session.getInstance(props,
	  new javax.mail.Authenticator() {
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(username, password);
		}
	  });
	
	try {
	    
		Message message = new MimeMessage(session);
		message.setFrom(new InternetAddress("from-email@gmail.com"));
		message.setRecipients(Message.RecipientType.TO,
			InternetAddress.parse("to-email@gmail.com"));
		message.setSubject("Testing Subject");
		message.setText("Dear Mail Crawler,"
			+ "\n\n No spam to my email, please!");
		
		//add attachment

		Transport.send(message);

		System.out.println("Done");

	} catch (MessagingException e) {
		throw new RuntimeException(e);
	}
	
    }

}
